package com.liuyjy.mybatisplus.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/**
 * @Author liuyjy
 * @Date 2022/1/18 13:08
 * @Description: 清除
 **/
public class CleanUtil {

    //项目中间路径
    private final static String midPath = "\\src\\main\\java\\com\\ppl\\dbgenerate\\";
    private Logger logger = LoggerFactory.getLogger(CleanUtil.class);

    //删除mapper下的文件
    public static boolean deleteFiles(File directory) {
        File[] files = directory.listFiles();
        if (files == null || files.length < 1) {
            return true;
        }
        for (File file : files) {
            if (file.isDirectory()) {
                deleteFiles(file);
            } else {
                file.delete();
            }
        }
        return true;
    }

    public static void clearResources() {
        String path = System.getProperty("user.dir") + "\\src\\main\\resources\\mapper";
        File file = new File(path);
        deleteFiles(file);
    }

    //获取文件
    private static File getFile(String name) {
        String path = System.getProperty("user.dir") + midPath + name;
        File file = new File(path);
        return file;
    }

}
